package net.lunjin.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.lunjin.bean.News;
import net.lunjin.service.NewsService;
import net.lunjin.service.OrganizationsService;
import net.lunjin.service.PeopleService;
import net.lunjin.service.RemarkService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import finaler.util.Page;
import finaler.util.PageList;

@Controller
@RequestMapping("index")
public class IndexController {
	
	@Autowired
	private OrganizationsService organizationsService;

	@Autowired
	private RemarkService remarkService;

	@Autowired
	private PeopleService peopleService;
	
	@Autowired
	private NewsService newsService;
	/**
	 * 首页
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/index.sm" )
	public String index(HttpServletRequest request) throws Exception {
		List<News> fmNewsList = newsService.getRandomRecord(0, 5);//首页随机5条负面新闻
		request.setAttribute("fmNewsList", fmNewsList);
		
		Page page = new Page(request);
		page.setRange(15);
		page.putParameter("searchkey", request.getParameter("searchkey"));
		page.putParameter("comin", request.getParameter("comin"));
		page.putParameter("iscom", request.getParameter("iscom"));
		page.putParameter("able", request.getParameter("able"));
		page.putParameter("combg", request.getParameter("combg"));
		page.putParameter("secu", request.getParameter("secu"));
		page.putParameter("speed", request.getParameter("speed"));
		page.putParameter("foruser", request.getParameter("foruser"));
		page.putParameter("network", request.getParameter("network"));
		page.putParameter("orgvip", request.getParameter("orgvip"));
		PageList organizationsList = organizationsService.getOrgList(page);//首页机构
		request.setAttribute("organizationsList", organizationsList);
		
		int wantCount = peopleService.getCount(0);//想入户数
		request.setAttribute("wantCount", wantCount);
		
		List<News> bbsNewsList = newsService.getBbsTopRecord(5);//5条交流新贴
		request.setAttribute("bbsNewsList", bbsNewsList);
		List<Map<String, Object>> newRemarkList = remarkService.getTopRemark(10);//5条最新评论
		request.setAttribute("newRemarkList", newRemarkList);
		List<News> knowNewsList = newsService.getTopRecord(1, 5);//5条最新投资知识
		request.setAttribute("knowNewsList", knowNewsList);
		
		List<News> tagList = newsService.getHotRecord(22, 50);//50条最热tag
		request.setAttribute("tagList", tagList);
		
		List<Map<String, Object>> proxy5List = peopleService.getTop5Proxy();//最新5个个人代理
		request.setAttribute("proxy5List", proxy5List);
		
		return "/index/index";
	}
	/**
	 * 伦敦金实时行情
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/ldj.sm" )
	public String ldj() throws Exception {
		return "/index/ldj";
	}
	
	/**
	 * 纸黄金实时行情
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/zhj.sm" )
	public String zhj() throws Exception {
		return "/index/zhj";
	}
	/**
	 * 黄金T+D
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/hjtd.sm" )
	public String hjtd() throws Exception {
		return "/index/hjtd";
	}
	/**
	 * 伦敦银实时行情
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/ldy.sm" )
	public String ldy() throws Exception {
		return "/index/ldy";
	}
	/**
	 * 纸白银实时行情
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/zby.sm" )
	public String zby() throws Exception {
		return "/index/zby";
	}

	/**
	 * 白银t+d实时行情
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/bytd.sm" )
	public String bytd() throws Exception {
		return "/index/bytd";
	}

	/**
	 * 白银t+d实时行情
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping( value="/operation/calendar.html" )
	public String calendar() throws Exception {
		return "/index/calendar";
	}

}
